﻿using System;
using System.ComponentModel.DataAnnotations;
using Foolproof;
using Lari.Configuration;
using Lari.Services.Data;

namespace Lari.Services.ViewModel
{
    public class QualificationModel
    {
        #region Primitive Properties
        public QualificationModel()
        {
            NotDegree = true;
        }
        public int Id
        {
            get;
            set;
        }
        [Required(ErrorMessage = MessageCode.Generic.ReguiredFldMsg)]
        [StringLength(30, ErrorMessage = MessageCode.Generic.LengthExceeded)]
        public string Name
        {
            get;
            set;
        }

        [RequiredIfTrue("NotDegree", ErrorMessage = MessageCode.Generic.RequiredPleaseSelect)]
        public int? Parent
        {
            get;
            set;
        }
        [StringLength(20)]
        public string UpdatedBy
        {
            get;
            set;
        }
        public DateTime? UpdatedOn
        {
            get;
            set;
        }
        [StringLength(20)]
        public string CreatedBy
        {
            get;
            set;
        }
        public DateTime? CreatedOn
        {
            get;
            set;
        }

        #endregion

        public bool NotDegree { get; set; }
    }

    public static partial class Extension
    {
        public static Qualification ConvertToEntityModel(this QualificationModel view)
        {

            var model = new Qualification
                            {
                                Id = view.Id,
                                Name = view.Name,
                                Parent = view.Parent,
                                
                            };

            return model;
        }

        public static QualificationModel ConvertToViewModel (this Qualification model)
        {
            var view = new QualificationModel
                           {
                               Id = model.Id,
                               Name = model.Name,
                               Parent = model.Parent,
                               
                           };

            return view;
            
        }
    }
}
